﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;


public partial class Controls_Banner_ctrBanner : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Initdata();
        }
    }

    private void Initdata()
    {
        Banner objBanner = new Banner();
        DataTable dtbBanner = new DataTable();
        dtbBanner = objBanner.GetAll();
        rptBanner.DataSource = dtbBanner;
        rptBanner.DataBind();
    }

    protected void rptBanner_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            ImageButton imgButton = (ImageButton)e.Item.FindControl("imgButton");
            imgButton.ImageUrl = Config.ROOT + Config.IMAGE_BANNER_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Images"));
            imgButton.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "BannerID"));
        }
    }

    protected void rptBanner_ItemCommand(object source, RepeaterCommandEventArgs e)
    {  
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        Banner objBanner = new Banner ();
        objBanner.LoadById(nID );
        switch (strCommand)
        {
            case "Image":
                Response.Redirect(Config.ROOT +  objBanner.Data.Link);
                break;
        }
    }
}